summaryrefslogtreecommitdiffstats
path: root/src/video_core/engines/sw_blitter/generate_converters.py
blob: f641564f7f2e9f4265870597e4e20249764a2061 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
# SPDX-License-Identifier: GPL-3.0-or-later

import re

class Format:
    def __init__(self, string_value):
        self.name = string_value
        tmp = string_value.split('_')
        self.component_type = tmp[1]
        component_data = re.findall(r"\w\d+", tmp[0])
        self.num_components = len(component_data)
        sizes = []
        swizzle = []
        for data in component_data:
            swizzle.append(data[0])
            sizes.append(int(data[1:]))
        self.sizes = sizes
        self.swizzle = swizzle

    def build_component_type_array(self):
        result = "{ "
        b = False
        for i in range(0, self.num_components):
            if b:
                result += ", "
            b = True
            result += "ComponentType::" + self.component_type
        result += " }"
        return result

    def build_component_sizes_array(self):
        result = "{ "
        b = False
        for i in range(0, self.num_components):
            if b:
                result += ", "
            b = True
            result += str(self.sizes[i])
        result += " }"
        return result

    def build_component_swizzle_array(self):
        result = "{ "
        b = False
        for i in range(0, self.num_components):
            if b:
                result += ", "
            b = True
            swizzle = self.swizzle[i]
            if swizzle == "X":
                swizzle = "None"
            result += "Swizzle::" + swizzle
        result += " }"
        return result

    def print_declaration(self):
        print("struct " + self.name + "Traits {")
        print("  static constexpr size_t num_components = " + str(self.num_components) + ";")
        print("  static constexpr std::array<ComponentType, num_components> component_types = " + self.build_component_type_array() + ";")
        print("  static constexpr std::array<size_t, num_components> component_sizes = " + self.build_component_sizes_array() + ";")
        print("  static constexpr std::array<Swizzle, num_components> component_swizzle = " + self.build_component_swizzle_array() + ";")
        print("};\n")

    def print_case(self):
        print("case RenderTargetFormat::" + self.name + ":")
        print("  return impl->converters_cache")
        print("    .emplace(format, std::make_unique<ConverterImpl<" + self.name + "Traits>>())")
        print("    .first->second.get();")
        print("  break;")

txt = """
R32G32B32A32_FLOAT
R32G32B32A32_SINT
R32G32B32A32_UINT
R32G32B32X32_FLOAT
R32G32B32X32_SINT
R32G32B32X32_UINT
R16G16B16A16_UNORM
R16G16B16A16_SNORM
R16G16B16A16_SINT
R16G16B16A16_UINT
R16G16B16A16_FLOAT
R32G32_FLOAT
R32G32_SINT
R32G32_UINT
R16G16B16X16_FLOAT
A8R8G8B8_UNORM
A8R8G8B8_SRGB
A2B10G10R10_UNORM
A2B10G10R10_UINT
A2R10G10B10_UNORM
A8B8G8R8_UNORM
A8B8G8R8_SRGB
A8B8G8R8_SNORM
A8B8G8R8_SINT
A8B8G8R8_UINT
R16G16_UNORM
R16G16_SNORM
R16G16_SINT
R16G16_UINT
R16G16_FLOAT
B10G11R11_FLOAT
R32_SINT
R32_UINT
R32_FLOAT
X8R8G8B8_UNORM
X8R8G8B8_SRGB
R5G6B5_UNORM
A1R5G5B5_UNORM
R8G8_UNORM
R8G8_SNORM
R8G8_SINT
R8G8_UINT
R16_UNORM
R16_SNORM
R16_SINT
R16_UINT
R16_FLOAT
R8_UNORM
R8_SNORM
R8_SINT
R8_UINT
X1R5G5B5_UNORM
X8B8G8R8_UNORM
X8B8G8R8_SRGB
"""

x = txt.split()
y = list(map(lambda a: Format(a), x))
formats = list(y)
for format in formats:
  format.print_declaration()

for format in formats:
  format.print_case()